import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;


public class Tools {
	
	static final String VTA_SITE = "http://www.vta.org/schedules/tdl/";
	static final String[] VTA_DIR = {
		"NO", "Northbound", 
		"SO", "Southbound",
		"EA", "Eastbound",
		"WE", "Westbound",
	};
	static final String[] VTA_DAY = {
		"WK", "Weekday", 
		"SU", "Sunday",
		"SA", "Saturday",
	};
	
    public static void main(String[] args) throws Exception {
    	// http://www.vta.org/schedules/tdl/SC_901NO_WK.tdl
    	
    	System.out.println("public abstract class Route {");
    	System.out.println("\tpublic static final Object[][] DATA = {");
    	int curRoute = -1;
    	for (int k = 0; k < RouteTable.DATA.length; ++k) {
        	for (int j = 0; j < VTA_DAY.length; j += 2) {
    	    	for (int i = 0; i < VTA_DIR.length; i += 2) {
	        		final String url = VTA_SITE + RouteTable.DATA[k][0] + VTA_DIR[i] + "_" + VTA_DAY[j] + ".tdl";
//	        		System.out.println(RouteTable.DATA[k][1] + ":" + url);

	        		final URL web = new URL(url);
	                final HttpURLConnection con =  (HttpURLConnection) web.openConnection();
	                con.setRequestMethod("GET");
	                con.connect();
	                if (con.getResponseCode() == 200) {
	                	final String s = RouteTable.DATA[k][1];
	                	final int r = Integer.parseInt(s.substring(0, s.indexOf(' ')));	// get route number
	                	if (curRoute != r) {
	                		if (curRoute != -1) {
			                	System.out.println("\t}},");
	                		}
	                		curRoute = r;
		                	System.out.println("\tnew Object[]{");
		                	System.out.println("\t" + r + ",\"" + RouteTable.DATA[k][1] + "\", null, new Object[][]{");
	                	}
	                	System.out.println(	   "\t\t{\"" + VTA_DIR[i+1] + " " + VTA_DAY[j+1] + "\",\"" + url + "\"},");
	                }
	                con.disconnect();
	        	}
	    	}
    	}
    }
}
